home *** CD-ROM | disk | FTP | other *** search
- Path: gail.ripco.com!mambuhl
- From: mambuhl@ripco.com (Martin Ambuhl)
- Newsgroups: comp.lang.c
- Subject: Convert String to Int?
- Date: 6 Mar 1996 07:21:45 GMT
- Organization: Ripco Communications, Inc.
- Message-ID: <4hjee9$qgd@gail.ripco.com>
- NNTP-Posting-Host: golden.ripco.com
-
- Stephen Parry <sparry@rahul.net> in <4hf3sk$k57@hustle.rahul.net> asks:
-
- >I have some numbers, range 0 to 999, stored as a strings. I need to
- >convert them to integers. Could I get some hints how to do this?
-
- #include <stdio.h> /* for sscanf */
- #include <stdlib.h> /* for atoi, strtol */
- int main()
- {
- int n;
- char s[256];
- /* ... */
- sscanf(s,"%d",&n); /* or */
- n = atoi(s); /* or */
- n = strtol(s, NULL, 10);
- /* ... */
- return 0;
- }
-
-
- --
- * Martin Ambuhl net: mambuhl@ripco.com
- * Chicago, IL (USA)
-